/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2017-07-21 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.pbpm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.itttq.gshop.domain.po.UserCartPo;
import com.itttq.gshop.pbpm.cmpt.mybatis.CustomInLanguage;
import com.itttq.gshop.pbpm.provider.UserCartSqlProvider;

@Mapper
public interface IUserCartMapper {
	/**
	 * 新增UserCartPo对象
	 * 
	 * @param UserCartPo
	 * @Author 迷蝶
	 * @return Integer
	 */
	@InsertProvider(type=UserCartSqlProvider.class,  method="addUserCart") 
	@Options(useGeneratedKeys = true, keyProperty = "id")
	public Integer addUserCart(UserCartPo userCart);

	/**
	 * 更新UserCartPo对象
	 * 
	 * @param userCartPo
	 * @Author 迷蝶
	 * @return Integer
	 */
	@UpdateProvider(type=UserCartSqlProvider.class,  method="updateUserCart") 
	public Integer updateUserCart(UserCartPo userCart);
	
	/**
	 * 根据ID删除UserCartPo对象
	 * 
	 * @param id
	 * @Author 迷蝶
	 * @return Integer
	 */
	@DeleteProvider(type=UserCartSqlProvider.class,  method="delUserCart") 
	public Integer delUserCartById(Integer id);

	/**
	 * 根据IDS删除UserCartPo对象
	 * 
	 * @param ids
	 * @Author 迷蝶
	 * @return List<UserCartPo>
	 */
	@Lang(CustomInLanguage.class)
	@Delete("DELETE FROM user_cart WHERE id IN (#{ids})")
	public Integer delUserCartByIds(@Param("ids") List<Integer> ids);
	
	/**
	 * 根据条件查找UserCartPo对象，默认根据ID降序
	 * 
	 * @param userCartPo
	 * @Author 迷蝶
	 * @return List<UserCartPo>
	 */
	@SelectProvider(type=UserCartSqlProvider.class,  method="findUserCarts") 
	public List<UserCartPo> findUserCarts(UserCartPo userCart);
	
	/**
	 * 根据条件查找记录总数
	 * 
	 * @param userCartPo
	 * @Author 迷蝶
	 * @return Integer
	 */
	@SelectProvider(type=UserCartSqlProvider.class,  method="findUserCartCount") 
	public Integer findUserCartCount(UserCartPo userCart);

	/**
	 * 根据ID查找UserCartPo对象
	 * 
	 * @param id
	 * @Author 迷蝶
	 * @return UserCartPo
	 */
	@SelectProvider(type=UserCartSqlProvider.class,  method="findUserCartById") 
	public UserCartPo findUserCartById(Integer id);

	/**
	 * 根据用户ID查找此用户购物车所有商品总数
	 * 
	 * @param userId
	 * @Author 迷蝶
	 * @return Integer
	 */
	@Select("SELECT SUM(number) as num FROM user_cart WHERE user_id=#{userId} GROUP BY user_id") 
	public Integer findWareSumByUserId(Integer userId);

	/**
	 * 
	 * 根据用户ID和购物车ID查找数据
	 * 
	 * @param userId	用户ID
	 * @param ids		购物车ID数组
	 * @Author 迷蝶
	 * @return List<UserCartPo>
	 */
	@Select("SELECT * FROM user_cart WHERE user_id=#{userId} and id IN (#{ids})") 
	@Lang(CustomInLanguage.class)
	public List<UserCartPo> findCartsByUserIdAndIds(@Param("userId") Integer userId, @Param("ids") Integer[] ids);
	
}